import App from './App'
import {
	VueJsonp
} from 'vue-jsonp'
Vue.use(VueJsonp)

// #ifdef H5

// #endif

import '@/styles/common.less'
import '@/styles/animate.css'

import WeuiWindow from '@/components/weui-window/'
Vue.component('WeuiWindow', WeuiWindow)


// #ifndef VUE3
import Vue from 'vue';

Vue.prototype.$toPage = function(url) {
	if (url.indexOf('tab') != -1) {
		uni.switchTab({
			url
		})
		return false;
	}
	uni.navigateTo({
		url
	});
}

Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif
//跳转
Vue.prototype.onSkip = function(url = '', other = '', callback = () => {}) {
	if (other) {
		if (url.indexOf('?') >= 0) {
			url += '&' + other
		} else {
			url += '?' + other
		}
	}
	if (url.indexOf("https://") == 0 || url.indexOf("http://") == 0) {
		uni.navigateTo({
			url: `/business/pages/business_tab/web?url=${encodeURIComponent(url)}`,
			fail () {
				uni.switchTab({
					url: `/business/pages/business_tab/web?url=${encodeURIComponent(url)}`
				})
			}
		})
	} else {
		uni.navigateTo({
			url,
			fail () {
				uni.switchTab({
					url
				})
			}
		})
	}
}
//动态设置nav文字
Vue.prototype.setNavTitle = function(tit) {
	uni.setNavigationBarTitle({
		title: tit
	})
}
//轮播图片预览
Vue.prototype.previewImage = function(index, imageList) {
	uni.previewImage({
		urls: imageList,
		current: index,
	})
}
//nav返回
Vue.prototype.goBack = function(time = 1000, page = 1) {
	setTimeout(() => {
		uni.navigateBack({
			delta: page
		});
	}, time)
}
//提示框
Vue.prototype.showToast = function(msg = '提示框', callback = () => {}) {
	uni.showToast({
		title: msg,
		icon: "none",
		mask: true,
		duration: 2000,
		success: callback

	});
}
//打电话
Vue.prototype.callPhone = function(tel) {
	// #ifdef APP-PLUS

	let platform = uni.getSystemInfoSync().platform
	switch (platform) {
		case 'android':
			plus.android.requestPermissions(
				["android.permission.CALL_PHONE"],
				function(resultObj) {
					// console.log(resultObj,'resultObj')
					var result = 0;
					for (var i = 0; i < resultObj.granted.length; i++) {
						var grantedPermission = resultObj.granted[i];
						// console.log('已获取的权限：' + grantedPermission);
						result = 1
					}
					for (var i = 0; i < resultObj.deniedPresent.length; i++) {
						var deniedPresentPermission = resultObj.deniedPresent[i];
						// console.log('拒绝本次申请的权限：' + deniedPresentPermission);
						result = 0
					}
					for (var i = 0; i < resultObj.deniedAlways.length; i++) {
						var deniedAlwaysPermission = resultObj.deniedAlways[i];
						// console.log('永久拒绝申请的权限：' + deniedAlwaysPermission);
						result = -1
					}
					// console.log(result);
					if (result == 1) {
						uni.makePhoneCall({
							phoneNumber: tel, //电话号码
							// success(ress) {
							// 	console.log("拨打电话成功",ress)
							// },
							// fail(err) {
							// 	console.log("拨打电话失败",'err')
							// }
						});
					} else {
						uni.showToast({
							title: "请开启拨号权限",
							icon: "error",
						})
					}
				},
				function(error) {
					console.log('申请权限错误：' + error.code + " = " + error.message);
				}
			);
			break;
		case 'ios':
			uni.makePhoneCall({
				phoneNumber: tel
			})
			break;
	}
	// #endif

	// #ifdef H5 | MP-WEIXIN
	uni.makePhoneCall({
		phoneNumber: tel
	})
	// #endif
}
// 跳转tab
Vue.prototype.switchTabbar = function(url) {
	uni.switchTab({
		url: url
	})
}
// 复制
Vue.prototype.copyText = function (data) {
	uni.setClipboardData({
		data,
		success: () => {
			uni.showToast({
				title: "复制成功"
			});
		}
	});
}